package com.moore.service.impl;

import com.moore.mapper.CommunityMapper;
import com.moore.mapper.StarMapper;
import com.moore.service.StarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StarServiceImpl implements StarService {
    @Autowired
    private StarMapper starMapper;
    @Autowired
    private CommunityMapper communityMapper;

    @Override
    public int addStar(Long communityId, Long candidateId) {
        int result =  starMapper.insert(communityId,candidateId);
        if (result > 0) {
            communityMapper.addStarCount(communityId);
            return result;
        } else return 0;
    }

    @Override
    public int deleteStar(Long communityId, Long candidateId) {
        int result =  starMapper.deleteByCommunityIdAndCandidateId(communityId,candidateId);
        if (result > 0) {
            communityMapper.reduceStarCount(communityId);
            return result;
        } else return 0;
    }
}
